{% extends 'base.html' %}
{% load buttons %}
{% load static %}
{% load custom_links %}
{% load helpers %}
{% load plugins %}

{% block title %}{{ provider }}{% endblock %}

{% block header %}
    <div class="row noprint">
        <div class="col-sm-8 col-md-9">
            <ol class="breadcrumb">
                <li><a href="{% url 'circuits:provider_list' %}">Providers</a></li>
                <li>{{ provider }}</li>
            </ol>
        </div>
        <div class="col-sm-4 col-md-3">
            <form action="{% url 'circuits:provider_list' %}" method="get">
                <div class="input-group">
                    <input type="text" name="q" class="form-control" />
                    <span class="input-group-btn">
                        <button type="submit" class="btn btn-primary">
                            <span class="fa fa-search" aria-hidden="true"></span>
                        </button>
                    </span>
                </div>
            </form>
        </div>
    </div>
    <div class="pull-right noprint">
        {% plugin_buttons provider %}
        {% if show_graphs %}
            <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#graphs_modal" data-obj="{{ provider.name }}" data-url="{% url 'circuits-api:provider-graphs' pk=provider.pk %}" title="Show graphs">
                <i class="fa fa-signal" aria-hidden="true"></i> Graphs
            </button>
        {% endif %}
        {% if perms.circuits.add_provider %}
            {% clone_button provider %}
        {% endif %}
        {% if perms.circuits.change_provider %}
            {% edit_button provider %}
        {% endif %}
        {% if perms.circuits.delete_provider %}
            {% delete_button provider %}
        {% endif %}
    </div>
    <h1>{{ provider }}</h1>
    {% include 'inc/created_updated.html' with obj=provider %}
    <div class="pull-right noprint">
        {% custom_links provider %}
    </div>
    <ul class="nav nav-tabs">
        <li role="presentation"{% if not active_tab %} class="active"{% endif %}>
            <a href="{{ provider.get_absolute_url }}">Provider</a>
        </li>
        {% if perms.extras.view_objectchange %}
            <li role="presentation"{% if active_tab == 'changelog' %} class="active"{% endif %}>
                <a href="{% url 'circuits:provider_changelog' slug=provider.slug %}">Change Log</a>
            </li>
        {% endif %}
    </ul>
{% endblock %}

{% block content %}
<div class="row">
	<div class="col-md-4">
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Provider</strong>
            </div>
            <table class="table table-hover panel-body attr-table">
                <tr>
                    <td>ASN</td>
                    <td>{{ provider.asn|placeholder }}</td>
                </tr>
                <tr>
                    <td>Account</td>
                    <td>{{ provider.account|placeholder }}</td>
                </tr>
                <tr>
                    <td>Customer Portal</td>
                    <td>
                        {% if provider.portal_url %}
                            <a href="{{ provider.portal_url }}">{{ provider.portal_url }}</a>
                        {% else %}
                            <span class="text-muted">&mdash;</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>NOC Contact</td>
                    <td class="rendered-markdown">{{ provider.noc_contact|render_markdown|placeholder }}</td>
                </tr>
                <tr>
                    <td>Admin Contact</td>
                    <td class="rendered-markdown">{{ provider.admin_contact|render_markdown|placeholder }}</td>
                </tr>
                <tr>
                    <td>Circuits</td>
                    <td>
                        <a href="{% url 'circuits:circuit_list' %}?provider={{ provider.slug }}">{{ circuits_table.rows|length }}</a>
                    </td>
                </tr>
            </table>
        </div>
        {% include 'inc/custom_fields_panel.html' with obj=provider %}
        {% include 'extras/inc/tags_panel.html' with tags=provider.tags.all url='circuits:provider_list' %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Comments</strong>
            </div>
            <div class="panel-body rendered-markdown">
                {% if provider.comments %}
                    {{ provider.comments|render_markdown }}
                {% else %}
                    <span class="text-muted">None</span>
                {% endif %}
            </div>
        </div>
        {% plugin_left_page provider %}
	</div>
	<div class="col-md-8">
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Circuits</strong>
            </div>
            {% include 'inc/table.html' with table=circuits_table %}
            {% if perms.circuits.add_circuit %}
                <div class="panel-footer text-right noprint">
                    <a href="{% url 'circuits:circuit_add' %}?provider={{ provider.pk }}" class="btn btn-xs btn-primary">
                        <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add circuit
                    </a>
                </div>
            {% endif %}
        </div>
    {% include 'inc/paginator.html' with paginator=circuits_table.paginator page=circuits_table.page %}
    {% plugin_right_page provider %}
    </div>
</div>
{% include 'inc/modal.html' with name='graphs' title='Graphs' %}
<div class="row">
    <div class="col-md-12">
        {% plugin_full_width_page provider %}
    </div>
</div>
{% endblock %}

{% block javascript %}
<script src="{% static 'js/graphs.js' %}?v{{ settings.VERSION }}"></script>
{% endblock %}
